import CryptoJS from 'crypto-js'

/**
 * 加密方法
 * @returns {string}
 */
export function encrypt(encryptString, key) {
	let aesKey = CryptoJS.enc.Utf8.parse(key);
	let aesEncryptString = CryptoJS.enc.Utf8.parse(encryptString);
	let encrypted = CryptoJS.AES.encrypt(aesEncryptString, aesKey, {
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7
	});
	return encrypted.toString();
}

/**
 * 解密方法
 * @returns {string}
 */
export function decrypt(decryptString, key) {
	let aesKey = CryptoJS.enc.Utf8.parse(key);
	let decrypt = CryptoJS.AES.decrypt(decryptString, aesKey, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7});
	return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}